package com.xfp.mapper;

import com.github.pagehelper.Page;
import com.xfp.anntation.AutoFill;
import com.xfp.enumclass.OperationClass;
import com.xfp.pojo.dto.PolicyDto;
import com.xfp.pojo.dto.PolicyQueryDto;
import com.xfp.pojo.entity.Policy;
import com.xfp.pojo.entity.PolicyVm;
import com.xfp.pojo.vo.VmPolicyVo;
import org.apache.ibatis.annotations.*;

@Mapper
public interface PolicyMapper {
    /**
     * 查询策略列表
     * @param dto
     * @return
     */
    Page<Policy> policyPage(PolicyQueryDto dto);

    /**
     * 新增策略
     * @param dto
     */
    @AutoFill(OperationClass.INSERT)
    @Insert("insert into tb_policy (policy_name,discount,create_time,update_time,create_user,update_user) values (#{policyName},#{discount},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void insertPolicy(PolicyDto dto);

    /**
     * 根据策略查询售货机
     *
     * @param id
     * @return
     */
    Page<PolicyVm> PolicyVmQuery(Integer id);

    /**
     * 修改策略
     * @param dto
     */
    @AutoFill(OperationClass.UPDATE)
    @Update("update tb_policy set policy_name =#{policyName},discount =#{discount},update_time = #{updateTime}, update_user = #{updateUser} where policy_id = #{policyId}")
    void updatePolicy(PolicyDto dto);

    /**
     * 删除策略
     * @param policyId
     */
    @Delete("delete from tb_policy where policy_id = #{policyId}")
    void deletePolicy(Integer policyId);

    /**
     * 查询售货机策略
     * @param innerCode
     * @return
     */
    @Select("select * from tb_vm_policy where inner_code = #{innerCode}")
    VmPolicyVo findVmPolicy(String innerCode);
}
